package com.elinkway.infinitemovies.bigdata;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;

import com.elinkway.infinitemovies.application.MoviesApplication;
import com.elinkway.infinitemovies.dao.PreferencesManager;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.utils.HostUtil;
import com.elinkway.infinitemovies.utils.IdUtils;
import com.elinkway.infinitemovies.utils.MoviesConstant;
import com.elinkway.infinitemovies.utils.MoviesUtils;
import com.elinkway.infinitemovies.utils.SharePreferenceManager;
import com.lvideo.http.bean.LVideoBaseBean;
import com.lvideo.http.bean.LVideoDataHull;
import com.lvideo.http.impl.LVideoHttpBaseParameter;
import com.lvideo.http.impl.LVideoHttpParameter;
import com.lvideo.http.impl.LVideoHttpTool;
import com.lvideo.http.parse.LVideoBaseParser;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

public class BigDataApi {
    public static final String VLEN = "vlen";
    public static final String UT = "ut";
    public static final String XH = "xh";
    public static final String ST = "st";
    public static final String URL = "url";
    public static final String RANK = "rank";
    public static final String EP = "ep";
    public static final String TY = "ty";
    public static final String UID = "uid";
    public static final String AUID = "auid";
    public static final String CID = "cid";
    public static final String AREA = "area";
    public static final String LID = "lid";
    public static final String SRC = "src";
    public static final String OSV = "osv";
    public static final String UUID = "uuid";
    public static final String P2 = "p2";
    public static final String PY = "py";
    public static final String NT = "nt";
    public static final String ILU = "ilu";
    public static final String AC = "ac";
    public static final String VER = "ver";
    public static final String LC = "lc";
    public static final String VID = "vid";
    public static final String CUR_URL = "cur_url";
    public static final String RY = "ry";

    public static final String CH = "ch";
    public static final String VT = "vt";
    public static final String PRG = "prg";
    public static final String BD = "bd";
    public static final String WEID = "weid";
    public static final String REID = "reid";
    public static final String APP = "app";
    public static final String ANDROID_ID = "android_id";
    public static final String INSTALL_ID = "install_id";
    public static final String SERIALNO = "serialno";
    public static final String STIME = "stime";
    public static final String ACODE = "acode";
    public static final String TARGETURL = "targeturl";
    public static final String ZID = "zid";
    public static final String R = "r";
    public static final String PT = "pt";
    public static final String P3 = "p3";
    public static final String RO = "ro";
    public static final String PID = "pid";
    public static final String BUCKET = "bucket";
    public static final String P1 = "p1";
    public static final String REF = "ref";
    public static final String CT = "ct";
    public static final String AP = "ap";
    public static final String OS = "os";
    public static final String BR = "br";
    public static final String AR = "ar";
    public static final String PV = "pv";
    public static final String CS = "cs";
    public static final String SSID = "ssid";
    public static final String LO = "lo";
    public static final String LA = "la";
    public static final String APPRUNID = "apprunid";
    public static final String STC = "stc";
    public static final String SID = "sid";
    public static final String PRL = "prl";
    public static final String CDEV = "cdev";
    public static final String CAID = "caid";
    public static final String CTIME = "ctime";
    public static final String PAY = "pay";
    public static final String JOINT = "joint";
    public static final String UTYPE = "utype";
    public static final String IPT = "ipt";
    public static final String CUSTID = "custid";
    public static final String TICK = "tick";
    public static final String PN = "pn";
    public static final String VC = "vc";
    public static final String AT = "at";
    public static final String OWNER = "owner";
    public static final String MID = "mid";
    public static final String ET = "et"; // 错误类型
    public static final String ERR = "err"; // 错误代码
    public static final String MODEL = "model";

    public static final String APP_NAME = "app_name";
    public static final String SOURCE = "source";
    public static final String IM = "im";
    public static final String IMSI = "imsi";
    public static final String WMAC = "wmac";

    public static class HOST {
        public static final String PRODUCT = "http://bigdata.shandianshipin.cn";
        public static final String TEST = IdUtils.BIGDATA_TEST_URL;
    }

    private static <T extends LVideoBaseBean, D> LVideoDataHull<T> request(
        LVideoHttpBaseParameter<T, D, ?> httpParameter) {
        LVideoHttpTool<T> handler = new LVideoHttpTool<T>();
        return handler.requsetData(httpParameter, MoviesApplication.getInstance());
    }

    private static String getHost() {
        if (BigDataStats.DEBUG) {
            return HOST.TEST;
        } else {
            return HOST.PRODUCT;
        }
    }

    /**
     * 环境上报
     *
     * @param parser
     * @param networkType
     * @param <T>
     * @param <D>
     * @return
     */
    public static <T extends LVideoBaseBean, D> LVideoDataHull<T> postEnv(
            LVideoBaseParser<T, D> parser, String networkType, String longitude,
            String latitude, String uid) {
        String url = getHost() + "/env/";
        Bundle params = new Bundle();
        params.putString(VER, BigDataConstants.API_VERSION);
        params.putString(P1, BigDataConstants.P1);
        params.putString(P2, BigDataConstants.P2);
        params.putString(P3, BigDataConstants.P3);
        params.putString(LC, BigDataConstants.DEVICEID);
        params.putString(UUID, MoviesConstant.UUID);
        params.putString(NT, networkType);
        params.putString(OS, BigDataConstants.OS);
        params.putString(OSV, BigDataConstants.OSVERSION);
        params.putString(APP, BigDataConstants.VERSION);
        params.putString(ANDROID_ID, BigDataConstants.ANDROIDID);
        params.putString(INSTALL_ID, BigDataConstants.INSTALLID);
        params.putString(SERIALNO, BigDataConstants.SERIALNO);
        params.putString(IM, BigDataConstants.DESIMEI);
        params.putString(IMSI, BigDataConstants.DESIMSI);
        params.putString(WMAC, BigDataConstants.WMAC);
        params.putString(STIME, System.currentTimeMillis() + "");
        params.putString(BD, BigDataConstants.BRAND);
        params.putString(XH, BigDataConstants.SERIAL);
        params.putString(RO, BigDataConstants.RESOLUTION);
        params.putString(BR, "");
        params.putString(SRC, "");
        params.putString(EP, "");
        params.putString(ZID, "");
        params.putString(R, BigDataUtils.ranLong());
        params.putString(CH, BigDataConstants.CHANNEL);
        params.putString(CS, String.valueOf(0));
        params.putString(SSID, BigDataConstants.SSID);
        params.putString(LO, longitude);
        params.putString(LA, latitude);
        params.putString(AUID, BigDataConstants.AUID);
        params.putString(UID, uid);
        params.putString(MODEL, BigDataConstants.SERIAL);
        params.putString(CTIME, System.currentTimeMillis() + "");
        params.putString(APPRUNID, BigDataConstants.APPRUNID);
        params.putString(APP_NAME, BigDataConstants.BD_APP_NAME);
        addTags(params);
        LogUtils.d("post env: " + params.toString());
        LVideoHttpParameter<T, D> httpParameter = new LVideoHttpParameter<T, D>(
                url, params, LVideoHttpParameter.Type.GET, parser, -1);
        return request(httpParameter);
    }

    /**
     * 启动，退出应用上报
     *
     * @param parser
     * @param ap
     * @param ar
     * @param acode
     * @param netType
     * @param <T>
     * @param <D>
     * @return
     */
    public static <T extends LVideoBaseBean, D> LVideoDataHull<T> postLaunchQuitAction(
            LVideoBaseParser<T, D> parser, String ap, String ar, String acode,
            String netType) {
        return postAction(null, ap, ar, acode, "-", "-", "-", "", "", "", netType, "", "", "", "");
    }

    /**
     * 日常推送上报
     *
     * @param parser
     * @param ap
     * @param ar
     * @param acode
     * @param cid
     * @param vid
     * @param pid
     * @param netType
     * @param <T>
     * @param <D>
     * @return
     */
    public static <T extends LVideoBaseBean, D> LVideoDataHull<T> postPushAction(
            LVideoBaseParser<T, D> parser, String ap, String ar, String acode,
            String cid, String vid, String pid, String netType) {
        return postAction(null, ap, ar, acode, cid, vid, pid, "", "", "", netType, "", "", "", "");
    }

    /**
     * 广告点击，曝光上报
     *
     * @param parser
     * @param ap
     * @param ar
     * @param acode
     * @param netType
     * @param <T>
     * @param <D>
     * @return
     */
    public static <T extends LVideoBaseBean, D> LVideoDataHull<T> postAdAction(
            LVideoBaseParser<T, D> parser, String ap, String ar, String acode,
            String netType) {
        return postAction(null, ap, ar, acode, "", "", "", "", "", "", netType, "", "", "", "");
    }

    /**
     * 下载，收藏，分享等上报
     *
     * @param parser
     * @param ap
     * @param ar
     * @param acode
     * @param netType
     * @param <T>
     * @param <D>
     * @return
     */
    public static <T extends LVideoBaseBean, D> LVideoDataHull<T> postCommonAction(
            LVideoBaseParser<T, D> parser, String ap, String ar, String acode,
            String cid, String vid, String pid, String zid, String rank, String cur_url, String netType, String uuid, String ilu, String reid, String bucket) {
        return postAction(null, ap, ar, acode, cid, vid, pid, zid, rank, cur_url, netType, uuid, ilu, reid, bucket);
    }

    /**
     * 日常操作上报（下载，收藏，分享等）
     *
     */
    public static void bigDataCommonReport(Map<String, String> dataMap, Context context) {
        if(dataMap == null){
            return;
        }
        BigDataStats.post(new BigDataCommonActionTask().setAcode(dataMap.get("acode")).setAR(BigDataConstants.AR_SUCCESS)
                .setAp(dataMap.get("ap")).setCid(dataMap.get("cid")).setVid(dataMap.get("vid"))
                .setPid(dataMap.get("pid")).setZid(dataMap.get("zid")).setCururl(dataMap.get("cur_url")).setRank(dataMap.get("rank"))
                .setNT(BigDataUtils.getNetType(context)).setUuid(dataMap.get("uuid")).setIlu(dataMap.get("ilu")).setReid(dataMap.get("reid")).setBucket(dataMap.get("bucket")));
    }

    /**
     * 广告大数据上报
     *
     * @param acode
     * @param ap
     * @param context
     */
    public static void bigDataAdReport(String acode, String ap, Context context) {
        BigDataStats.post(new BigDataAdActionTask().setAcode(acode).setAR(BigDataConstants.AR_SUCCESS)
                .setAp(ap)
                .setNT(BigDataUtils.getNetType(context)));
    }

    /**
     * 日常上报
     *
     * @param parser
     * @param ap
     * @param ar
     * @param acode
     * @param cid
     * @param vid
     * @param pid
     * @param netType
     * @param <T>
     * @param <D>
     * @return
     */
    private static <T extends LVideoBaseBean, D> LVideoDataHull<T> postAction(
            LVideoBaseParser<T, D> parser, String ap, String ar, String acode,
            String cid, String vid, String pid, String zid, String rank, String cur_rul, String netType, String uuid, String ilu, String reid, String bucket) {
        String url = getHost() + "/op/";
        Bundle params = new Bundle();
        params.putString(VER, BigDataConstants.API_VERSION);
        params.putString(P1, BigDataConstants.P1);
        params.putString(P2, BigDataConstants.P2);
        params.putString(P3, BigDataConstants.P3);
        params.putString(ACODE, acode);
        try {
            params.putString(AP, URLEncoder.encode(ap, "UTF-8")); // 动作属性
        } catch (UnsupportedEncodingException e) {
            params.putString(AP, ap);
        }
        params.putString(AR, ar);// 动作结果
        params.putString(CID, cid);
        params.putString(PID, pid);
        params.putString(VID, vid);
        params.putString(UID, BigDataUtils.getUserUid());
        params.putString(UUID, TextUtils.isEmpty(uuid) ? MoviesConstant.UUID : uuid);
        params.putString(LC, BigDataConstants.DEVICEID);
        params.putString(APP, BigDataConstants.VERSION);
        params.putString(ANDROID_ID, BigDataConstants.ANDROIDID);
        params.putString(INSTALL_ID, BigDataConstants.INSTALLID);
        params.putString(SERIALNO, BigDataConstants.SERIALNO);
        params.putString(IM, BigDataConstants.DESIMEI);
        params.putString(IMSI, BigDataConstants.DESIMSI);
        params.putString(WMAC, BigDataConstants.WMAC);
        params.putString(STIME, System.currentTimeMillis() + "");
        params.putString(CUR_URL, cur_rul);
        params.putString(CH, BigDataConstants.CHANNEL);
        params.putString(AUID, BigDataConstants.AUID);
        params.putString(ILU, TextUtils.isEmpty(ilu) ? BigDataUtils.isLoginUser() : ilu);
        params.putString(REID, TextUtils.isEmpty(reid)? "":reid);
        params.putString(AREA, "");
        params.putString(BUCKET, TextUtils.isEmpty(bucket)? "":bucket);
        params.putString(RANK, rank);
        params.putString(TARGETURL, "");
        params.putString(ZID, zid);
        params.putString(LID, "");
        params.putString(R, BigDataUtils.ranLong());
        params.putString(NT, netType);
        params.putString(TICK, "");
        params.putString(PN, BigDataConstants.PACKAGE_NAME);
        params.putString(VC, BigDataConstants.VERSION);
        params.putString(AT, "");
        params.putString(CTIME, System.currentTimeMillis() + "");
        params.putString(APPRUNID, BigDataConstants.APPRUNID);
        params.putString(APP_NAME, BigDataConstants.BD_APP_NAME);
        addTags(params);
        LogUtils.d("post action: " + params.toString());
        LVideoHttpParameter<T, D> httpParameter = new LVideoHttpParameter<T, D>(
                url, params, LVideoHttpParameter.Type.GET, parser, -1);
        return request(httpParameter);
    }

    /**
     * 播放上报
     *
     * @param parser
     * @param ac      直播（init，play，end）
     * @param pt      ac为time时上报(播放时长)
     * @param ut      空
     * @param uuid
     * @param cid     直播取 liveid
     * @param pid
     * @param vid     点播必须上报
     * @param vlen    轮播和直播取值 6000
     * @param ry      重试次数
     * @param ty      播放类型 本地 3 在线 0 直播 1
     * @param vt      点播上报对应的编号，直播和轮播上报编号对应的字符串(直播，轮播) (码流 乐视资源才上报)
     * @param url     直播url编码
     * @param ref     播放页来源地址
     * @param py      播放属性 第一个参数：专辑名：name 第二个参数：播放站点：src
     * @param prg     播放进度
     * @param zid     专题id 为空,1.7.4修改为在专题tab下上传themeId。
     * @param lid     直播id 为空
     * @param netType
     * @param caid    cde为每个app指定的唯一ID init动作才上报
     * @param ctime   当前时间
     * @param owner   1：乐视网自有媒资；0：外网媒资
     * @param mid     [播放外网媒资资源（owner=0
     *                ）时，必须上报]推荐部相关产品上报自有的global_id值，云视频上报云视频客户方媒资的id
     * @return
     */
    public static <T extends LVideoBaseBean, D> LVideoDataHull<T> postPlay(
            LVideoBaseParser<T, D> parser, String ac, int pt, String ut,
            String uuid, String cid, String pid, String vid, long vlen, int ry,
            String ty, String vt, String url, String ref, String py, int prg,
            String zid, String lid, String netType, String caid, long ctime, int owner,
            String mid, String source) {
        String post_url = getHost() + "/pl/";
        Bundle params = new Bundle();
        params.putString(VER, BigDataConstants.API_VERSION);
        params.putString(P1, BigDataConstants.P1);
        params.putString(P2, BigDataConstants.P2);
        params.putString(P3, BigDataConstants.P3);
        params.putString(AC, ac); // 动作代码 上报时机
        params.putString(PT, String.valueOf(pt)); // 播放时长 上报心跳动作time时才上报
        params.putString(UT, String.valueOf(ut)); // 动作耗时
        params.putString(UID, BigDataUtils.getUserUid());
        params.putString(LC, BigDataConstants.DEVICEID);
        params.putString(APP, BigDataConstants.VERSION);
        params.putString(ANDROID_ID, BigDataConstants.ANDROIDID);
        params.putString(INSTALL_ID, BigDataConstants.INSTALLID);
        params.putString(SERIALNO, BigDataConstants.SERIALNO);
        params.putString(IM, BigDataConstants.DESIMEI);
        params.putString(IMSI, BigDataConstants.DESIMSI);
        params.putString(WMAC, BigDataConstants.WMAC);
        params.putString(STIME, System.currentTimeMillis() + "");
        params.putString(AUID, BigDataConstants.AUID);
        params.putString(UUID, uuid); // uuid切流
        params.putString(CID, cid);// 选填
        params.putString(PID, pid);// 选填
        params.putString(VID, vid);// 选填
        params.putString(VLEN, String.valueOf(vlen));// 视频时长
        params.putString(CH, BigDataConstants.CHANNEL);
        params.putString(RY, String.valueOf(ry));
        params.putString(TY, ty);// 播放类型 在线0 缓冲3
        params.putString(VT, vt);// 播放器的vtype
        params.putString(URL, url);
        params.putString(REF, ref);// 播放页来源地址
        params.putString(R, BigDataUtils.ranLong());
        params.putString(PV, MoviesUtils.getClientVersionName());// 播放器版本(未知)--直接用app的版本
        try {
            params.putString(PY, URLEncoder.encode(py, "UTF-8")); // 业务线自己维护
        } catch (UnsupportedEncodingException e) {
            params.putString(PY, py);
        }
        params.putString(ST, "");// 播放类型是轮播时必填
        params.putString(ILU, BigDataUtils.isLoginUser());// 0是登陆用户,1非登陆用户注：云视频无需上报
        params.putString(WEID, "");
        params.putString(AP, "1");
        params.putString(PRG, String.valueOf(prg));// 用户上报动作时视频时间轴上的时间点 s
        params.putString(ZID, zid);// 专题id
        params.putString(LID, lid);// 直播id
        params.putString(R, BigDataUtils.ranLong());
        params.putString(NT, netType);
        params.putString(UTYPE, "");
        params.putString(STC, "");// 影响起播的各阶段时长 (未知)
        params.putString(SID, "");
        params.putString(PRL, "1");// 预加载 播放动作ac=play时必须上报
        params.putString(CDEV, BigDataConstants.CDE_VERSION);// 播放动作ac=init时必须上报
        params.putString(CAID, caid);// 播放动作ac=init时必须上报 cde为每个app指定的唯一ID
        params.putString(CTIME, String.valueOf(ctime));// 播放动作发生时客户端的时间(北京时间)
        params.putString(PAY, "0");// 0：免费 1：收费视频试看
        // 2：付费观看播放动作ac=play时必须上报，其他动作时不上报。
        params.putString(JOINT, "0");// 0：无广告 1：有广告已拼接
        // 2：有广告未拼接播放动作ac=play时必须上报，其他动作时不上报。
        params.putString(IPT, "0");// 0：直接点播 1：连播 2：切换码流
        params.putString(CUSTID, "");
        params.putString(APPRUNID, BigDataConstants.APPRUNID);
        params.putString(OWNER, String.valueOf(owner));
        params.putString(MID, mid);
        params.putString(APP_NAME, BigDataConstants.BD_APP_NAME);
        params.putString(SOURCE, source);
        addTags(params);
        LogUtils.d("post play: " + params.toString());
        LVideoHttpParameter<T, D> httpParameter = new LVideoHttpParameter<T, D>(
                post_url, params, LVideoHttpParameter.Type.GET, parser, -1);
        return request(httpParameter);
    }

    /**
     * 错误上报
     *
     * @param parser
     * @param et      播放错误 pl
     * @param err     错误代码 (详细区分)
     * @param netType
     * @param uuid    播放错误才上报
     * @return
     */
    public static <T extends LVideoBaseBean, D> LVideoDataHull<T> postError(
            LVideoBaseParser<T, D> parser, String et, String err, String netType,
            String uuid) {
        String url = getHost() + "/er/";
        Bundle params = new Bundle();
        params.putString(VER, BigDataConstants.API_VERSION);
        params.putString(P1, BigDataConstants.P1);
        params.putString(P2, BigDataConstants.P2);
        params.putString(P3, BigDataConstants.P3);
        params.putString(ET, et);
        params.putString(ERR, err); // 动作属性
        params.putString(LC, BigDataConstants.DEVICEID);
        params.putString(APP, BigDataConstants.VERSION);
        params.putString(ANDROID_ID, BigDataConstants.ANDROIDID);
        params.putString(INSTALL_ID, BigDataConstants.INSTALLID);
        params.putString(SERIALNO, BigDataConstants.SERIALNO);
        params.putString(IM, BigDataConstants.DESIMEI);
        params.putString(IMSI, BigDataConstants.DESIMSI);
        params.putString(WMAC, BigDataConstants.WMAC);
        params.putString(STIME, System.currentTimeMillis() + "");
        params.putString(AUID, BigDataConstants.AUID);
        params.putString(NT, netType);
        params.putString(OS, BigDataConstants.OS);
        params.putString(OSV, BigDataConstants.OSVERSION);
        params.putString(APP, BigDataConstants.VERSION);
        params.putString(BD, BigDataConstants.BRAND);
        params.putString(XH, BigDataConstants.SERIAL);
        params.putString(MODEL, BigDataConstants.SERIAL);
        params.putString(RO, BigDataConstants.RESOLUTION);
        params.putString(BR, "");
        params.putString(EP, "");// 错误属性
        params.putString(PID, "");
        params.putString(VID, "");
        params.putString(ZID, "");
        params.putString(R, BigDataUtils.ranLong());
        params.putString(UID, BigDataUtils.getUserUid());
        params.putString(UUID, uuid);
        params.putString(CTIME, System.currentTimeMillis() + "");
        params.putString(APPRUNID, BigDataConstants.APPRUNID);
        params.putString(APP_NAME, BigDataConstants.BD_APP_NAME);
        addTags(params);
        LogUtils.d("post error: " + params.toString());
        LVideoHttpParameter<T, D> httpParameter = new LVideoHttpParameter<T, D>(
                url, params, LVideoHttpParameter.Type.GET, parser, -1);
        return request(httpParameter);
    }

    /**
     * 页面上报
     */
    public static <T extends LVideoBaseBean, D> LVideoDataHull<T> postPageShow(String cur_url, Map<String, String> map) {
        String url = getHost() + "/pgv/";
        Bundle params = new Bundle();
        params.putString(VER, BigDataConstants.API_VERSION);
        params.putString(P1, BigDataConstants.P1);
        params.putString(P2, BigDataConstants.P2);
        params.putString(P3, BigDataConstants.P3);
        params.putString(CID, map.get(CID) == null ? "": map.get(CID));
        params.putString(PID, map.get(PID) == null ? "": map.get(PID));
        params.putString(VID, map.get(VID) == null ? "": map.get(VID));
        params.putString(UID, BigDataUtils.getUserUid());
        params.putString(NT, map.get(NT) == null ? "": map.get(NT));
        params.putString(UUID, MoviesConstant.UUID);
        params.putString(LC, BigDataConstants.DEVICEID);
        params.putString(APP, BigDataConstants.VERSION);
        params.putString(ANDROID_ID, BigDataConstants.ANDROIDID);
        params.putString(INSTALL_ID, BigDataConstants.INSTALLID);
        params.putString(SERIALNO, BigDataConstants.SERIALNO);
        params.putString(IM, BigDataConstants.DESIMEI);
        params.putString(IMSI, BigDataConstants.DESIMSI);
        params.putString(WMAC, BigDataConstants.WMAC);
        params.putString(STIME, System.currentTimeMillis() + "");
        params.putString(CUR_URL, cur_url);
        params.putString(REF, map.get(REF) == null ? "": map.get(REF));// 页面来源
        params.putString(CT, "2");   //来源类型,暂时写死，都当做站内---2
        params.putString(CH, BigDataConstants.CHANNEL);
        params.putString(AUID, BigDataConstants.AUID);
        params.putString(ILU, BigDataUtils.isLoginUser());
        params.putString(AREA, map.get(AREA) == null ? "": map.get(AREA));
        params.putString(ZID, map.get(ZID) == null ? "": map.get(ZID));
        params.putString(R, BigDataUtils.ranLong());
        params.putString(CTIME, System.currentTimeMillis() + "");
        params.putString(NT, map.get(NT) == null ? "": map.get(NT));
        params.putString(APPRUNID, BigDataConstants.APPRUNID);
        params.putString(APP_NAME, BigDataConstants.BD_APP_NAME);
        addTags(params);
        LogUtils.d("post action: " + params.toString());
        LVideoHttpParameter<T, D> httpParameter = new LVideoHttpParameter<T, D>(
                url, params, LVideoHttpParameter.Type.GET, null, -1);
        return request(httpParameter);
    }

    /**
     * 页面展示上报
     *
     */
    public static void bigDataPageShowReport(String cur_url, Map<String, String> map, Context context) {
        if(TextUtils.isEmpty(cur_url)){
            return;
        }
        map.put(NT, BigDataUtils.getNetType(context));
        BigDataStats.post(new BigDataPageShowTask().setCurUrl(cur_url).setParamMap(map));
    }

    public static Map<String, String> createDataMap(String acode, String ap, String ar, String cid,
                                                    String pid, String vid){
        Map<String,String> map = new HashMap<String,String>();
        map.put("acode", acode);
        map.put("ap", ap);
        map.put("ar", ar);
        map.put("cid", cid);
        map.put("pid", pid);
        map.put("vid", vid);
        return map;
    }

    /**
     * 搜索上报
     *
     */
    public static <T extends LVideoBaseBean, D> LVideoDataHull<T> postSearchAction(Bundle extraParams) {
        String value = SharePreferenceManager.getVaule(MoviesApplication.getInstance(), MoviesHttpApi.TEST_HOST, "");
        String url = HostUtil.getSearchUploadHost(value);
        Bundle params = new Bundle();
        params.putString(VER, BigDataConstants.API_VERSION);
        params.putString("from", "mobile_03");
        params.putString("uid", "");
        params.putString("imei", MoviesUtils.getPhoneImei());
        params.putString("device_id", BigDataConstants.DEVICEID);
        params.putString("time", System.currentTimeMillis()+"");
        params.putAll(extraParams);
        params.putString("version", MoviesUtils.getClientVersionName());
        LVideoHttpParameter<T, D> httpParameter = new LVideoHttpParameter<T, D>(
                url, params, LVideoHttpParameter.Type.GET, null, -1);
        return request(httpParameter);
    }

    /**
     * 页面展示上报
     *
     */
    public static void bigDataSearchReport(BigDataSearchBean searchBean) {
        Bundle params = new Bundle();
        params.putString("module", searchBean.getModule());
        params.putString("click_area", searchBean.getClickArea());
        params.putString("query", searchBean.getQuery());
        params.putString("suggest_text", searchBean.getSuggestText());
        params.putString("action_code", searchBean.getActionCode());
        params.putString("eid", searchBean.getEid());
        params.putString("gid", searchBean.getGid()==null?"":searchBean.getGid());
        params.putString("experiment_id", searchBean.getExperimentId());
        params.putString("is_trigger", searchBean.getIsTrigger());
        params.putString("parent_eid", searchBean.getParentEid());
        params.putString("position", searchBean.getPosition());
        params.putString("status", searchBean.getStatus());
        BigDataStats.post(new BigDataSearchActionTask().setExtraData(params));
    }

    private static void addTags(Bundle params) {
        if (params != null) {
            String tags = PreferencesManager.getInstance().getTags();
            if (!TextUtils.isEmpty(tags)) {
                params.putString(MoviesHttpApi.TAGS, tags);
            }
        }
    }
}
